from EmpVoting.Stat import BaseStatFromFieldCollection

class NetworkStatFromAgentField(BaseStatFromFieldCollection):

    def __init__(self, fieldName, statOp):
        '''
        Constructor
        
        Supported stat operations are listed in BaseStatFromFieldCollection.
        '''
        self.FieldName = fieldName
        self.StatOp = statOp
        
    def Apply(self, network):
        valList = []
        for agent in network.agentList:
            valList.append(agent.__dict__[self.FieldName])
            
        statResult = self._CalcStatFromList(valList, self.StatOp)
        network.__dict__["agent_" + self.FieldName + "_" + self.StatOp] = statResult